{include file="public/common" /}


<form class="layui-form" id="order_form">
    <ul class="layui-nav" lay-filter="">
        <li class="layui-nav-item <?php echo !isset($param['order_status_id'])?'layui-this':'' ?> "><a href="{:url('/addons/execute/seller-order-list_')}">全部</a></li>
        {volist name="order_status" id="status_item"}
        <li class="layui-nav-item <?php echo isset($param['order_status_id'])&&$param['order_status_id']==$key?'layui-this':'' ?> "><a href="{:url('/addons/execute/seller-order-list_',['order_status_id'=>$key])}">{$status_item}</a></li>
        {/volist}
    </ul>
    <input type="hidden" name="order_status_id" value="<?php echo isset($param['order_status_id'])?$param['order_status_id']:'' ?>">
    <div class="layui-form-item" style="margin-top: 10px">
        <div class="layui-inline">
            <div class="layui-input-inline">
                <input type="text" name="search_" value="<?php echo isset($param['search_'])?$param['search_']:''?>" autocomplete="off" class="layui-input" placeholder="搜索订单号/用户名称..">
            </div>
        </div>
        <div class="layui-inline">
            <button type="submit" class="layui-btn" >筛选</button>
            <a class="layui-btn" name="export" value="1" onclick="export_data()">导出数据</a>
        </div>
    </div>
</form>

<div>
    <table class="layui-table" width="900px">
        <thead>
        <tr style="text-align: center;">
            <td>订单号</td>
            <td>用户</td>
            <td>用户电话</td>
            <td>收货地址</td>
            <td>备注</td>
            <td>操作</td>
        </tr>
        </thead>
        <tbody>
        {volist name="list_" id="order"}
        <tr style="text-align: center;">
            <td> {$order.order_id}</td>
            <td> {$order.user_name}</td>
            <td> {$order.telephone}</td>
            <td> {$order.address}</td>
            <td> {$order.memo}</td>
            <td>
                <button class="layui-btn layui-btn-small" onclick="model('/addons/execute/seller-order-order_details?order_id={$order.order_id}')">订单详情</button>
                {if condition="$order.order_status_id == $wait_for_order"}
                <button class='layui-btn layui-btn-small' onclick='accept_order("{$order.order_id}")'>确认接单</button>
                {/if}
                {if condition="$order.order_status_id == $accept_order"}
                <button class='layui-btn layui-btn-small' onclick='send_goods("{$order.order_id}")'>确认发货</button>
                {/if}
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    {$list_->render()}
</div>

<script>
    /**
     * 导出数据
     */
    function export_data() {
        $data = $('#order_form').serialize();
        var href = "/addons/execute/seller-order-list_?export=1&" + $data;
        window.open(href);
        return false;
    }
    /**
     * 发货接单
     * @param order_id
     */
    function accept_order(order_id) {
        var s = confirm("确认接单");
        if(s){
            $.ajax({
                url: '{:addon_url("seller://order/accept_order")}' ,
                dataType: "json",
                async: true,
                data: {
                    "order_id": order_id
                },
                type: "post",
                success: function (res) {
                    if (res.code == 0) {
                        location.reload();
                    }
                    else {
                        layer.alert(res.msg, {icon: 5});
                    }
                },
                error: function (xhr, errorText, errorStatus) {
                    alert('fail');
                }
            });
        }
    }
    /**
     * 发货操作
     * @param order_id
     */
    function send_goods(order_id) {
        var s = confirm("确认发货");
        if(s){
            $.ajax({
                url: '{:addon_url("seller://order/querenshouhuo")}' ,
                dataType: "json",
                async: true,
                data: {
                    "order_id": order_id
                },
                type: "post",
                success: function (res) {
                    if (res.code == 0) {
                        location.reload();
                    }
                    else {
                        layer.alert(res.msg, {icon: 5});
                    }
                },
                error: function (xhr, errorText, errorStatus) {
                    alert('fail');
                }
            });
        }
    }
</script>